package definite.Guide.Book.CoreSwingComponent.JComponentClass;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JButton;

public class ActionChangedListener implements PropertyChangeListener {

	private JButton button;

	public ActionChangedListener(JButton btn) {
		this.button = btn;
	}

	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		String propertyName = evt.getPropertyName();
		if (propertyName.endsWith(Action.NAME)) {
			String text = (String) evt.getNewValue();
			button.setText(text);
			button.repaint();
		} else if (propertyName.equals("enabled")) {
			Boolean enableState = (Boolean) evt.getNewValue();
			button.setEnabled(enableState.booleanValue());
			button.repaint();
		} else if (propertyName.equals(Action.SMALL_ICON)) {
			Icon icon = (Icon) evt.getNewValue();
			button.setIcon(icon);
			button.invalidate();
			button.repaint();
		}
	}

}
